﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace DemoGame1
{
    public abstract class VisibleGameEntity : GameEntity
    {
        protected List<My2DSprite> sprites;
        public bool Drawbound = false;
        public List<My2DSprite> Sprites
        {
            get { return sprites; }
            set { sprites = value; }
        }
        protected int nSprites;

        private bool _Visible = true;

        public bool Visible
        {
            get { return _Visible; }
            set
            {
                _Visible = value;
                for (int i = 0; i < nSprites; i++)
                {
                    sprites[i].Visible = value;
                }
            }
        }
        protected Vector2 _Size;

        public Vector2 Size
        {
            get { return _Size; }
            set { _Size = value; }
        }

        protected Vector2 _TopLeft;

        public Vector2 TopLeft
        {
            get { return _TopLeft; }
            set
            {
                _TopLeft = value;

                for (int i = 0; i < nSprites; i++)
                {
                    sprites[i].Position = value;
                }
            }
        }
        protected bool bUpdate = true;
        public Rectangle BoundRect=new Rectangle();
        virtual public void Update(GameTime gameTime)
        {

            if (bUpdate)
            {
                for (int i = 0; i < nSprites; i++)
                {
                    sprites[i].Update(gameTime);
                }
            }

        }
        virtual public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {

            for (int i = 0; i < nSprites; i++)
            {

                sprites[i].Draw(spriteBatch, gameTime);
            }

        }

        virtual public void Draw(SpriteBatch sb, GameTime gameTime, Vector2 _TopLeft, Vector2 _Size)
        {
        }

        virtual public bool IsClicked(Vector2 point)
        {

            if ((point.X >= _TopLeft.X) &&
                (point.X <= _TopLeft.X + _Size.X) &&
                (point.Y >= _TopLeft.Y) &&
                (point.Y <= _TopLeft.Y + _Size.Y))
                return true;
            return false;

        }
        virtual public void SetScale(float scale)
        {
            foreach (My2DSprite t in sprites)
            {
                t.Scale = scale;
            }
            //int h =   scale;
            BoundRect.Width = (int)(BoundRect.Width * scale);
            BoundRect.Height = (int)   (BoundRect.Height* scale);

            

        }
        virtual public void SetTransform(SpriteEffects se)
        {
            foreach (My2DSprite t in sprites)
            {
                t.SpriteEffects = se;
            }
        }
        virtual public void SetOrigin(Vector2 tt)
        {
            foreach (My2DSprite t in sprites)
            {
                t.Origin = tt;
            }
        }
        virtual public void adjustTopleft(float x, float y)
        {
            Vector2 newpos = new Vector2(x, y);
            TopLeft = newpos;
            foreach (My2DSprite t in sprites)
            {
                t.Position = newpos;
            }
        }
        virtual public bool Collidewith(VisibleGameEntity t)
        {
            if(Visible && t.Visible)
            return BoundRect.Intersects(t.BoundRect);
            return false;
        }
    }
}
